# -*- coding: utf-8 -*-
"""
author:码同学 极光
date:2023/11/19
desc: 
sample: 
"""
import os
import random

from locust import HttpUser, constant, between, task, FastHttpUser


#class LoginTest(HttpUser): 普通进程
from utils import getExcelList, getExcelDict


class LoginTest(FastHttpUser): #协程
    host = 'http://82.156.74.26:9088/pinter'  # 可选
    #wait_time = between(1, 3) #思考时间
    # 静态变量 只读取一次
    excel_list = getExcelDict('case.xlsx')

    @task
    def login(self):
        url = '/com/login'
        params = random.choice(self.excel_list)
        print(params)
        #随机
        data = {"userName": params.get('usr'), 'password': params.get('psw')}
        with self.client.post(url=url,data=data, catch_response=True) as response:
            json  = response.json()
            if json.get('message')=='success':
                response.success()
            else:
                response.failure(json)


if __name__ == '__main__':
    os.system('locust -f loucstLogin.py --web-port 8091  -u 300 -r 10 -t 1h30m20s')